package in.iqing.control.util;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import in.iqing.app.R;

/**
 * Created by neavo on 2014/7/1.
 */

public class ToastUtil {

	public static void showError(Context ctx, int code, String msg) {
		Toast toast;

		// 解析服务器错误返回-1
		if (code == -1) {
			toast = Toast.makeText(ctx, R.string.common_error_500, Toast.LENGTH_SHORT);
		} else if (code == 400) {
			toast = Toast.makeText(ctx, R.string.common_error_400, Toast.LENGTH_SHORT);
		} else if (code == 401) {
			toast = Toast.makeText(ctx, R.string.common_error_401, Toast.LENGTH_SHORT);
		} else if (code == 403) {
			toast = Toast.makeText(ctx, R.string.common_error_403, Toast.LENGTH_SHORT);
		} else if (code == 404) {
			toast = Toast.makeText(ctx, R.string.common_error_404, Toast.LENGTH_SHORT);
		} else if (code == 450) {
			toast = Toast.makeText(ctx, R.string.common_error_450, Toast.LENGTH_SHORT);
		} else if (code == 500) {
			toast = Toast.makeText(ctx, R.string.common_error_500, Toast.LENGTH_SHORT);
		} else if (code == 600) {
			toast = Toast.makeText(ctx, R.string.common_error_600, Toast.LENGTH_SHORT);
		} else if (code == 601) {
			toast = Toast.makeText(ctx, R.string.common_error_601, Toast.LENGTH_SHORT);
		} else if (code == 602) {
			toast = Toast.makeText(ctx, R.string.common_error_602, Toast.LENGTH_SHORT);
		} else if (code == 603) {
			toast = Toast.makeText(ctx, R.string.common_error_603, Toast.LENGTH_SHORT);
		} else if (code == 604) {
			toast = Toast.makeText(ctx, R.string.common_error_604, Toast.LENGTH_SHORT);
		} else if (!TextUtils.isEmpty(msg)) {
			toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
		} else {
			toast = Toast.makeText(ctx, R.string.common_error_unknown, Toast.LENGTH_SHORT);
		}

		toast.show();
	}

	public static synchronized void show(Context ctx, String msg) {
		Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
		toast.show();
	}

	public static synchronized void show(Context ctx, int resid) {
		Toast toast = Toast.makeText(ctx, resid, Toast.LENGTH_SHORT);
		toast.show();
	}

	public static synchronized void show(Context ctx, String msg, int gravity) {
		Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
		toast.setGravity(gravity, 0, 0);
		toast.show();
	}

	public static synchronized void show(Context ctx, int resid, int gravity) {
		Toast toast = Toast.makeText(ctx, resid, Toast.LENGTH_SHORT);
		toast.setGravity(gravity, 0, 0);
		toast.show();
	}

	public static synchronized void show(Context ctx, String msg, int gravity, int x, int y) {
		Toast toast = Toast.makeText(ctx, msg, Toast.LENGTH_SHORT);
		toast.setGravity(gravity, x, y);
		toast.show();
	}

	public static synchronized void show(Context ctx, int resid, int gravity, int x, int y) {
		Toast toast = Toast.makeText(ctx, resid, Toast.LENGTH_SHORT);
		toast.setGravity(gravity, x, y);
		toast.show();
	}
}
